//index.js
//获取应用实例
const app = getApp()
const util = require('../../utils/util.js')
Page({
    data: {
        motto: 'Hello World',
        userInfo: {},
        hasUserInfo: false,
        // canIUse: wx.canIUse('button.open-type.getUserInfo'),
        winWidth: '',
        winHeight: '',
        code: '',
        encryptedData: '',
        iv: '',
        sessionId: '',
        setps: '',
        userm: '',
        date: '',
        usertype: true,
        adds: {},
        myadd: '',
        sport: {},
        minqw: '',
        maxqw: '',
        array: 0,
        animationData: {},
        bgimage: '/image/bg.jpg',
        canvass: true,
        titlebg: '',
        txs:''
    },
    //事件处理函数
    onLoad: function(e) {

      console.log(wx.getStorageSync('userimg'))
      wx.getSystemInfo({
        success: res => {
console.log(res)
          this.setData({
            winWidth: res.windowWidth,
            winHeight: res.screenHeight
          })
        }
      })
        var name = wx.getStorageSync('username'); //名字

        var add = wx.getStorageSync('add'); //地址
        var xx = wx.getStorageSync('xx'); //星星数量
        var setp = wx.getStorageSync('setp'); //步数
      var m = (wx.getStorageSync('setp') * 0.8).toFixed(2); //米
        var time = wx.getStorageSync('time'); //时间
        var dwidth = wx.getStorageSync('w');
        var ywidth = wx.getStorageSync('y');
      var tx = wx.getStorageSync('userimg');
        var bgss = wx.getStorageSync('titlebg');

        var context = wx.createCanvasContext('mycanvas');
        var dom = this.data.userInfo
        context.setFillStyle('#ffffff')
        context.fillRect(0, 0, wx.getStorageSync('w'), wx.getStorageSync('y'));
        context.setStrokeStyle('#E1E1E1');
        context.setLineWidth(0.5)
        context.strokeRect(10, 10, wx.getStorageSync('w') - 20, wx.getStorageSync('y') - 20);
        context.setFillStyle('#ffdc33')
        context.fillRect(20, 20, wx.getStorageSync('w') - 40, wx.getStorageSync('y') - 150);
        context.drawImage(tx, 30, 30, 70, 70)
        context.setFillStyle('black')
        context.setFontSize(12)
        context.fillText(name, 120, 50);
        util.xhxx(context, xx, 1, 2, 3, 4, 5, 55)
        context.setFontSize(14)
        context.fillText(add, 120, 100);


        if (dwidth >= 320 && dwidth <= 374) {
            context.drawImage(bgss, (wx.getStorageSync('w') - 256) / 2, 150, 256, 80)
        } else if (dwidth >= 375 && dwidth <= 414) {
            context.drawImage(bgss, (wx.getStorageSync('w') - 256) / 2, 220, 256, 80)
        }


        context.setTextAlign('center')
        context.setFillStyle('#4c4c4c')
        context.setFontSize(48)
        context.fillText(setp + '步', wx.getStorageSync('w') / 2, wx.getStorageSync('y') - 200)
        context.setFontSize(22)
        context.fillText('≈' + m + 'M', wx.getStorageSync('w') / 2, wx.getStorageSync('y') - 170)
        context.setFontSize(14)
        context.fillText(time, wx.getStorageSync('w') / 2, wx.getStorageSync('y') - 150)
        context.drawImage('/image/eqm.png', wx.getStorageSync('w') - 110, wx.getStorageSync('y') - 110, 90, 90)
        context.drawImage('/image/logo.png', (wx.getStorageSync('w') - 89) / 2, wx.getStorageSync('y') - 35, 89, 15)
        
        // context.draw();
        setTimeout(function() {
            util.showLogin('正在加载')
          context.fill();
            context.draw();
        }, 600)

    },
    saveImage: function() {
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: wx.getStorageSync('w'),
            height: wx.getStorageSync('y'),
            destWidth: wx.getStorageSync('w') * 4,
            destHeight: wx.getStorageSync('y') * 4,
            canvasId: 'mycanvas',
            quality: 1,
            success: function(res) {
                wx.saveImageToPhotosAlbum({
                    filePath: res.tempFilePath,
                    success(ress) {
                        console.log(ress)
                    }
                })
            }
        })
    }



})